package com.wy.system.controller;

import com.alibaba.fastjson.JSON;
import com.wy.common.result.Result;
import com.wy.model.entity.Course;
import com.wy.system.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/course")
public class CourseController {

  @Autowired
  private CourseService courseService;

  //查询所有课程
  @GetMapping("findAll")
  public Result findAllCourse() {
    List<Course> list = courseService.list();
    Object[] classArr = list.toArray();
    return Result.ok(classArr);
  }

  //修改 根据id查询
  @GetMapping("findCourseById")
  public Result findCourseById(@PathVariable("id") Integer id) {
    Course course = courseService.getById(id);
    return Result.ok(course);
  }

  //修改 更新数据库
  @PostMapping("update")
  public Result updateCourse(@RequestBody Course course) {
    boolean isSuccess = courseService.updateById(course);
    if (isSuccess) {
      return Result.ok();
    } else {
      return Result.fail();
    }
  }
}
